Selected Row Handling

Add Copy Record Button

Description
This customization allows adding a Copy Button to a Show Table Records page and handle the processing for the selected row on the table.
Variables
Table Control Class
Select a table control
Copy Button
Select the copy button
Table Name
Select the database table.
Applies to
TableControl class
Code
 
/// 
/// Override the ${Copy Button}_Click and get selected records
/// and create new database records.
/// 
public override void ${Copy Button}_Click(object sender, EventArgs args)
{
    try
    {
        DbUtils.StartTransaction();
        ${Table Name}TableControlRow[] selectedRecords = this.GetSelectedRecordControls();
        if ((selectedRecords.Length > 0)) 
        {           
            foreach (${Table Name}TableControlRow ${Table Name}Rec in selectedRecords)
            {
                ${${Table Name}RecordClassName} newRec = new ${${Table Name}RecordClassName}();
                newRec = (${${Table Name}RecordClassName})${Table Name}Rec.GetRecord().CopyRecord();
                newRec.Save();
            }
            DbUtils.CommitTransaction();
        }
    }
    catch (Exception ex)
    {
        DbUtils.RollBackTransaction();
        
        // Report the error message to the user
        BaseClasses.Utils.MiscUtils.RegisterJScriptAlert(this, "UNIQUE_SCRIPTKEY", ex.Message);
    }
    finally
    {
        DbUtils.EndTransaction();
    }
}
 

Terms of Service Privacy Statement